package housing.task2.stale.fileIO;

import housing.task1.actor.Renter;

import java.io.IOException;
import java.util.ArrayList;

public class ReaderOld {

    public static ArrayList<Renter> getRenters(String fileSource) {

        ArrayList<Renter> res = new ArrayList<Renter>();
        HumanReadableFormat format =
                HumanReadableFormat.extractExtension(fileSource);
        switch (format) {
            case CSV:
                try {
                    res = getRentersFromCSV(fileSource);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case JSON:
                try {
                    res = getRentersFromJSON(fileSource);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case YAML:
                break;
            default:
        }// switch

        return res;

    }// getRenter();


    private static ArrayList<Renter> getRentersFromCSV(String file) throws IOException {
        ArrayList<Renter> res = new ArrayList<Renter>();
        ArrayList<String[]> stringArrays = Parser.parseCSV(file);

        String name;
        String address;
        for (String[] str : stringArrays) {
            name = str[0];
            address = str[1];
            res.add(new Renter());//res.add(new Renter.xsd(name, Address));
        }

        return res;

    }// ArrayList<Renter.xsd> getRentersFromCSV(...)

    private static ArrayList<Renter> getRentersFromJSON(String file) throws IOException {
        ArrayList<Renter> res = new ArrayList<Renter>();
        ArrayList<String[]> stringArrays = Parser.parseJSON(file);

        String name;
        String address;
        String isRepairRequested;
        for (String[] str : stringArrays) {
            name = str[0];
            address = str[1];
            isRepairRequested = str[2];
            boolean flag = isRepairRequested.equals("true") ? true : false;
            res.add(new Renter());//res.add(new Renter.xsd(name, Address, flag));
        }
        return res;
    }// ... getRentersFromJSON(...)

}// class ReaderFromFile
